/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.databox.enumeration;

import java.util.Enumeration;

import twaver.Element;
import twaver.TDataBox;
import demo.DemoNodeFactory;

public class EnumerationDemo {

	public static void main(String[] args) {
		TDataBox box = new TDataBox();
		DemoNodeFactory.createAll(box);

		System.out.println("============ Depth First Enumeration ============");
		Enumeration e = box.depthFirstEnumeration();
		while(e.hasMoreElements()){
			Element element = (Element)e.nextElement();
			print(element);
		}
		
		System.out.println("============ Depth First Enumeration From Nework ============");
		e = box.depthFirstEnumeration(box.getElementByName("Network"));
		while(e.hasMoreElements()){
			Element element = (Element)e.nextElement();
			print(element);
		}	
        
		System.out.println("============ Breadth First Enumeration ============");
		e = box.breadthFirstEnumeration();
		while(e.hasMoreElements()){
			Element element = (Element)e.nextElement();
			print(element);
		}	
        
		System.out.println("============ Breadth First Enumeration From Nework ============");
		e = box.breadthFirstEnumeration(box.getElementByName("Network"));
		while(e.hasMoreElements()){
			Element element = (Element)e.nextElement();
			print(element);
		}	
	}
	
	public static void print(Element element){
		Element parent = element.getParent();
		while(parent != null){
			System.out.print(" ---");
			parent = parent.getParent();
		}
		System.out.println(" " + element.getName());
	}

}